package com.qisi.demo;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

public class LocalDtaTimeDemo {

    public static void main(String[] args) {

        LocalDateTime now = LocalDateTime.now();


        // LocalDateTime 转 timestamp
        Instant instant = now.atZone(ZoneId.systemDefault()).toInstant();
        long timestamp = instant.toEpochMilli();


        // timestamp 转 LocalDateTime
        Instant instant2 = Instant.ofEpochMilli(timestamp);
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant2, ZoneId.systemDefault());


        // 时间差
        Duration between = Duration.between(now, localDateTime);

        System.out.println("timestamp = " + timestamp);
        System.out.println("now = " + now);
        System.out.println("localDateTime = " + localDateTime);
        System.out.println("between = " + between.getSeconds());

    }

}
